/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} n
 * @return {ListNode}
 */
head = [1,2,3,4,5], n = 2
var removeNthFromEnd = function(head, n) {
        let dummy= new ListNode(0)
        dummy.next=head
        let curr=dummy
        let curr1=dummy
        for(let i=0;i<n;i++)
        {
            curr=curr.next
        }
        while(curr.next)
       {
            curr=curr.next
            curr1=curr1.next       
       }
       curr1.next=curr1.next.next     
       return dummy.next   
};
console.log(removeNthFromEnd(head,n))

